{php include wl_template('common/header');}
<div class="app-content">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#">消息推送</a></li>
    </ul>
    <div class="panel" style="padding: 20px 20px 0 20px;">
        <div class="alert alert-warning">
            正在进行消息推送, 请不要关闭窗口.
        </div>
        <div class="form-horizontal ng-cloak" ng-controller="processor">
            <dl class="dl-horizontal">
                <dt>总计可推送用户数量</dt>
                <dd>{{pragress}}</dd>
                <dt>整体进度条</dt>
                <dd>
                    <div class="progress">
                        <div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="{{file}}" aria-valuemin="0" aria-valuemax="100" style="width: {{file}}%">
                            <span class="sr-only">{{file}}% Complete (success)</span>
                        </div>
                    </div>
                </dd>
            </dl>
        </div>
        <script>
            require(['angular'], function(angular){
                angular.module('app', []).controller('processor', function($scope, $http){
                    var total = {$fannum};
                    var i = 0;
                    var pindex = 0;
                    var res = 0;
                    var proc = function() {
                        if(res == 3 && i != 0 ){
                            layer.open({
                                content: '恭喜您，商户动态推送完成！共计'+total+'条，成功'+i+'条',
                                yes: function(index, layero){
                                    location.href = '{php echo web_url("member/userlabel/labellist");}';
                                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                                }
                            });
                            return;
                        }
                        $http.post('{php echo web_url("member/userlabel/senddyning",array("id" => $id,"firsttext"=>$firsttext,"remark"=>$remark,"content"=>$content,"source"=>$source,"url" => $url));}', {
                            "pindex":pindex,"success":i
                        }).success(function(dat){
                            if(dat.result == 1){
                                i = dat.success;
                                pindex ++;
                                $scope.file = (i/total)*100;
                                $scope.pragress = i + '/' + total;
                            }else if(dat.result == 3){
                                res = 3;
                            }
                            proc();
                        }).error(function(){
                            proc();
                        });
                    }
                    proc();
                });
                angular.bootstrap(document, ['app']);
            });
        </script>
    </div>
</div>
{php include wl_template('common/footer');}
